﻿#include "page_g.h"
#include "ui_page_g.h"
#include <vector>
#include <cmath>

//================================ Гриша ================================
double mathExpect_geometric(double & p)
{
    return (1 - p) / p;
}
double variance_geometric(double & p)
{
    return (1 - p) / (p * p);
}
double stndDeviation_geometric(double & p)
{
    return sqrt(variance_geometric(p));
}
std::vector <double> getPk(unsigned int & n, double & p)
{
    std::vector <double> Pk;
    for(int i = 0; i <= n; i++)
        Pk.push_back( pow((1 - p), i) * p );
    return Pk;
}
//================================================================

page_g::page_g(QWidget *parent)
	: page_clean(parent)
{
	ui = new Ui::page_gClass();
	ui->setupUi(this);

    QObject::connect(ui->checkBox, SIGNAL(clicked(bool)), ui->checkBox_disp, SLOT(setChecked(bool)));
    QObject::connect(ui->checkBox, SIGNAL(clicked(bool)), ui->checkBox_f_raspr, SLOT(setChecked(bool)));
    QObject::connect(ui->checkBox, SIGNAL(clicked(bool)), ui->checkBox_sr_kv_otkl, SLOT(setChecked(bool)));
    QObject::connect(ui->checkBox, SIGNAL(clicked(bool)), ui->checkBox_math_o, SLOT(setChecked(bool)));
    QObject::connect(ui->checkBox, SIGNAL(clicked(bool)), ui->checkBox_rad_raspr, SLOT(setChecked(bool)));
}

page_g::~page_g()
{
    delete ui;
}

void page_g::inputGeom(unsigned int *n, double *p)
{
    (*n) = ui->input_n->value();
    (*p) = ui->input_p->value();
}
void page_g::on_calc_btn_clicked()
{
    unsigned int n;
    double p;
    inputGeom(&n, &p);
    std::vector <double> v = getPk(n,p);
    if(ui->checkBox_rad_raspr->checkState()==Qt::Checked)
    {
        show_Rad(v);
    }
    if(ui->checkBox_math_o->checkState()==Qt::Checked)
    {
        emit appendToLog(QString("M(X) = ")+QString::number(mathExpect_geometric(p)));
    }
    if(ui->checkBox_disp->checkState()==Qt::Checked)
    {
        emit appendToLog(QString("D(X) = ")+QString::number(variance_geometric(p)));
    }
    if(ui->checkBox_sr_kv_otkl->checkState()==Qt::Checked)
    {
        emit appendToLog(QString("&#963;(X) = ")+QString::number(stndDeviation_geometric(p)));
    }
    if(ui->checkBox_f_raspr->checkState()==Qt::Checked)
    {
        show_Graph(v);
    }
    //if(ui->checkBox_mng->checkState()==Qt::Checked)           //calc_Mng();
    //if(ui->checkBox_graph->checkState()==Qt::Checked)
    emit appendToLog("<hr />");
}
